/*
 * Copyright (c) 2009 Team TypeZero
 *
 * This file is part of ZebBowling
 *
 * ZebBowling is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * ZebBowling is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ZebBowling. If not, see <http://www.gnu.org/licenses/>.
 **/

package org.zebbowling.world;

/**
 *
 * @author markvismonte
 */
public class BowlingPlayer extends Object
    {
    private BowlingScore[] scores;
    //Array of scores
    private int playerNum, power, curve;

    /**
     * Creates a new player
     * @param playerNum
     */
    public BowlingPlayer(int playerNum)
        {
        super();
        this.playerNum = playerNum;
        scores = new BowlingScore[10];
        power = 1;
        curve = BowlingFrame.GAME_WIDTH/2;
        }

    public boolean setScore(int pos, int score,int count)
        {
        if (pos < 10 && pos >= 0)
            {
            scores[pos] = new BowlingScore(score, count);
            return true;
            }
        return false;
        }

    public void addToSparesAndStrikes(int score, int pos)
        {
        for (int i = 0; i < pos; i++)
            if (scores[i].getScore() >= 10)
                scores[i].addToScore(score);
        }

    public int getScore(int pos)
        {
        return pos < 10 && pos >= 0 && scores[pos] != null? scores[pos].getScore(): 0;
        }

    public int totalScore()
        {
        int sum = 0;
        for (int i = 0; i < scores.length; i++)
            if (scores[i] != null)
                sum += scores[i].getScore();
        return sum;
        }

    public int getCurve() {
        return curve;
        }

    public void setCurve(int curve) {
        this.curve = curve;
        }

    public int getPower() {
        return power;
        }

    public void setPower(int power) {
        this.power = power;
        }

    public String toString()
        {
        String ret = "Player " + playerNum + "\nScores:";
        for (int i = 0; i < scores.length; i++)
            ret += (scores[i] != null?scores[i].getScore():0) + "\t";
        return ret;
        }
    }
